package com.yonyougov.devops.cruxcisupport.committrace;

import com.yonyougov.devops.cruxcisupport.committrace.dto.CommitTestIdAndStatusDto;
import com.yonyougov.devops.cruxcisupport.committrace.dto.CommitTestIdInStatusInDto;
import com.yonyougov.devops.cruxcisupport.committrace.dto.CommitTraceEntityByInDto;
import com.yonyougov.devops.cruxcisupport.committrace.vo.CommitTraceKeyValueVo;
import com.yonyougov.devops.cruxcisupport.committrace.vo.CommitTracePageVo;
import com.yonyougov.devops.cruxcisupport.committrace.vo.QueryCommitTracePageDto;
import com.yonyougov.devops.fwc.core.dao.BaseDao;
import com.yonyougov.devops.fwc.core.entity.Pagination;
import com.yonyougov.devops.fwc.core.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

/**
 * t_commit_trace服务实现
 */
@Service
public class CommitTraceServiceImpl extends BaseServiceImpl<CommitTraceEntity, BigInteger> implements CommitTraceService {
    @Autowired
    private CommitTraceDao commitTraceDao;

    @Override
    public BaseDao<CommitTraceEntity, BigInteger> getDao() {
        return commitTraceDao;
    }
    //<!--用户自定义代码开始-->

    /**
     * 查询提测历史
     * 条件: 提测单id
     *
     * @param queryCommitTracePageDto [com.yonyougov.devops.cruxcisupport.committrace.vo.QueryCommitTracePageDto]
     * @return [com.yonyougov.devops.fwc.core.entity.Pagination: com.yonyougov.devops.cruxcisupport.committrace.vo.CommitTracePageVo]
     */
    @Override
    public Pagination<CommitTracePageVo> findPageBy(QueryCommitTracePageDto queryCommitTracePageDto) {
        List<CommitTracePageVo> commitTracePageVoList = commitTraceDao.findPageBy(queryCommitTracePageDto);
        int totalCount = commitTraceDao.countBy(queryCommitTracePageDto);

        return new Pagination<>(queryCommitTracePageDto.getMax(), queryCommitTracePageDto.getPageNum(), totalCount, commitTracePageVoList);
    }


    /**
     * 根据提测id和状态查询追踪记录
     *
     * @param commitTestIdAndStatusDto com.yonyougov.devops.cruxcisupport.committrace.dto.CommitTestIdAndStatusDto
     * @return java.util.List
     */
    @Override
    public List<CommitTraceEntity> findByCommitTestIdAndStatus(CommitTestIdAndStatusDto commitTestIdAndStatusDto) {
        return commitTraceDao.findByCommitTestIdAndStatus(commitTestIdAndStatusDto);
    }

    /**
     * 根据提测id和状态查询追踪记录,取每个状态的第一条
     *
     * @param commitTestIdAndStatusDto com.yonyougov.devops.cruxcisupport.committrace.dto.CommitTestIdAndStatusDto
     * @return java.util.List
     */
    @Override
    public List<CommitTraceEntity> findGroupInFristByCommitTestIdAndStatus(CommitTestIdAndStatusDto commitTestIdAndStatusDto) {
        return commitTraceDao.findGroupInFristByCommitTestIdAndStatus(commitTestIdAndStatusDto);
    }

    @Override
    public List<CommitTraceKeyValueVo> findGroupByCommitTestIdStatus(CommitTestIdInStatusInDto commitTestIdInStatusInDto) {
        return commitTraceDao.findGroupByCommitTestIdStatus(commitTestIdInStatusInDto);
    }

    /**
     * 通用in查询
     *
     * @param commitTraceEntityByInDto com.yonyougov.devops.cruxcisupport.committrace.dto.CommitTraceEntityByInDto
     * @return java.util.List
     */
    @Override
    public List<CommitTraceEntity> findByIn(CommitTraceEntityByInDto commitTraceEntityByInDto) {
        return commitTraceDao.findByIn(commitTraceEntityByInDto);
    }


    //<!--用户自定义代码结束-->
}
